// function qs(ele) {
//     return document.querySelector(ele)
// }

// 接口地址：https://www.apifox.cn/apidoc/shared-36f0cbc0-9064-44bc-850a-805e263bf494/api-25827426

const qs = ele=>document.querySelector(ele)

axios.defaults.baseURL='http://124.223.14.236:3001/api'
init()
 async function init(){
  const {data} = await axios({
    url:'/city/province',
    method:'GET',
})
// console.log(data);

const provin=data.data.map(
    ele=>`<option value="${ele.province}">${ele.name}</option>`).join('')
    // console.log(provin)
    qs('#province').innerHTML='	<option value="">请选择省份</option>'+provin
      qs('#province').value ='34'
    //   const provinceCode=qs('#province').value
    //   console.log(provinceCode);


      const {data:datab}=await axios({
        url:'/city/city',
        method:'GET',
        params:{
           provinceCode:'34'
        },
      })
// console.log(datab);

const provi=datab.data.map(
    ele=>`<option value="${ele.city}">${ele.name}</option>`).join('')
    // console.log(provi)
    qs('#city').innerHTML='	<option value="">请选择城市</option>'+provi
      qs('#city').value ='01'


      const {data:datac}=await axios({
        url:'/city/area',
        method:'GET',
        params:{
           provinceCode:'34',
           cityCode:'01'
        },
      })
// console.log(datac);

const pro=datac.data.map(
    ele=>`<option value="${ele.area}">${ele.name}</option>`).join('')
    // console.log(pro)
    qs('#county').innerHTML='	<option value="">请选择区县</option>'+pro
      qs('#county').value ='02'
      
}

qs('#province').addEventListener('change',async function(){
    console.log(this.value);
    // let ppp=this.value
    const {data:datab}=await axios({
        url:'/city/city',
        method:'GET',
        params:{
           provinceCode:this.value
        },
      })
// console.log(datab);

const provi=datab.data.map(
    ele=>`<option value="${ele.city}">${ele.name}</option>`).join('')
    // console.log(provi)
    qs('#city').innerHTML='	<option value="">请选择城市</option>'+provi
    //   qs('#city').value ='01'  


    qs('#county').innerHTML = '<option value="">请选择区县</option>'
})






qs('#city').addEventListener('change',async function(){
    console.log(qs('#province').value);
    console.log(this.value);
    const {data:datac}=await axios({
        url:'/city/area',
        method:'GET',
        params:{
           provinceCode:qs('#province').value,
           cityCode:this.value,
        },
      })
    // console.log(datac);
    
    const pro=datac.data.map(
    ele=>`<option value="${ele.area}">${ele.name}</option>`).join('')
    console.log(pro)
    qs('#county').innerHTML='	<option value="">请选择区县</option>'+pro
    //   qs('#county').value ='02'
    })